package it.uniroma2.dtk.drp;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class DRPtoSVMFormatter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			BufferedReader inSVM = new BufferedReader(new FileReader(new File(args[0])));
			BufferedReader inDRP = new BufferedReader(new FileReader(new File(args[1])));
			BufferedWriter out = new BufferedWriter(new FileWriter(new File(args[2])));
			inDRP.readLine(); //Skipping first line with dimensions
			String drpLine = inDRP.readLine();
			String svmLine = inSVM.readLine();
			while (drpLine != null) {
				if (svmLine == null)
					throw new Exception("Reached end of drp file but not of svm file!");
				String output = svmLine + " " + drpLine.substring(drpLine.indexOf("1:")) + " |EV|";
				out.write(output);
				out.newLine();
				drpLine = inDRP.readLine();
				svmLine = inSVM.readLine();
			}
			if (svmLine != null)
				throw new Exception("Reached end of svm file but not of drp file!");
			inDRP.close();
			inSVM.close();
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
